﻿using HDSmartCommunity.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace HDSmartCommunity.DAL
{
    public class UserDAL
    {
        public User GetUser(User user)
        {
            try
            {
                string strSql = "SELECT * FROM user WHERE username='" + user.username + "' AND password='" + user.password + "'";

                CommFN<User> fn = new CommFN<User>();
                return fn.GetData(strSql);
            }
            catch
            {
                return null;
            }
        }

        public bool UpdatePwd(User user)
        {
            string strSql = "UPDATE user SET password='"+user.password+"' WHERE ID="+user.ID;

            CommFN<User> fn = new CommFN<User>();
            return fn.ExecFN(strSql);
        }

        public List<User> GetAllUser()
        {
            try
            {
                string strSql = "SELECT * FROM user";

                CommFN<User> fn = new CommFN<User>();
                return fn.GetDataList(strSql);
            }
            catch
            {
                return null;
            }
        }
    }
}
